package 美团;

public class _704_二分查找 {
    public int search(int[] nums, int target) {
        int index = bs(nums, 0, nums.length, target);
        return index;
    }

    private int bs(int[] nums, int begin, int end, int target) {
        if (begin == end) return -1;
        int mid = begin + ((end - begin) >> 1);
        if (nums[mid] == target) return mid;
        if (nums[mid] > target) {
            return bs(nums, mid + 1, end, target);
        } else {

            return bs(nums, begin, mid, target);
        }
    }

    public static void main(String[] args) {
        _704_二分查找 o = new _704_二分查找();
        System.out.println(o.search(new int[]{-1, 0, 3, 5, 9, 12}, 9));
    }
}
